home *** CD-ROM | disk | FTP | other *** search
/ Apple Color Graphics Sampler / Apple Color Graphics Sampler.iso / English / Screen Savers / Dark Side of the Mac / FaderShell / Invert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-16  |  5.7 KB  |  251 lines  |  [TEXT/MPS ]

  1. /*
  2.  
  3.     Invert.c - A simple screen fader that runs as a MultiFinder
  4.     application.  Is typically launched by Lunarmobiscuit's
  5.     Darkness MultiFinder screen saver program.
  6.     
  7.     copyright © 1989 by Tom Dowdy
  8.     All rights reserved
  9.     
  10.     Modifications
  11.         Aug    5 1989        TED        basic fade working as standalone code
  12.         Nov 30 1989        TED        file converted to a standalone application
  13.         
  14.     This is about as simple as a screen blackout can get.  Not very useful,
  15.     but a good starting point for creating your own screen saver.
  16.     
  17. */
  18.  
  19. #include <QuickDraw.h>
  20. #include <Windows.h>
  21. #include <Memory.h>
  22. #include <Dialogs.h>
  23. #include <Resources.h>
  24.  
  25.  
  26. typedef struct
  27.     {
  28.     Boolean    isResource;        // are these settings from a resource?
  29.     Boolean    doInvert;        // do we invert on fade?
  30.     } SettingsRecord, *SettingsPtr, **SettingsHandle;
  31.  
  32. typedef struct
  33.     {
  34.     SettingsHandle    theSettings;    // what options could someone want?
  35.     Rect            maxRect;        // Size of the fading area
  36.     } BlackoutRecord, *BlackoutPtr, **BlackoutHandle;
  37.  
  38.  
  39. #include "Blackout.h"
  40.     
  41.  
  42. /* ------------------------------------------------------------------------------------    */
  43. #pragma segment Initialize
  44.  
  45. // FORWARD DECALARES, DoSetupDialog MUST be first for entry point
  46.  
  47. SettingsHandle    GetSettings();
  48. void WriteSettings(SettingsHandle theSettings);
  49.  
  50. void DoSetupDialog(SetupParamBlock *theSetup)
  51. {
  52.     short            hit;
  53.     DialogPtr        dPtr;
  54.     SettingsHandle    theSettings;
  55.     
  56.     CenterWindow('DLOG', kSetupDialogID, nil);
  57.     dPtr = GetNewDialog(kSetupDialogID, nil, (WindowPtr)-1);
  58.     if (dPtr != nil)
  59.         {
  60.         SetPort(dPtr);
  61.         SetUserItem (dPtr, 3, DefaultUserItem);
  62.         SetUserItem (dPtr, 6, AboutUserItem);
  63.         theSettings = GetSettings();
  64.         if (theSettings != nil)
  65.             SetItemCtlValue(dPtr, 5, (**theSettings).doInvert);
  66.             
  67.         ShowWindow(dPtr);
  68.         do
  69.             {
  70.             ModalDialog((ModalFilterProcPtr) OKCancelFilterProc, &hit);
  71.             if (hit == 5)
  72.                 SetItemCtlValue(dPtr, 5, !GetItemCtlValue(dPtr, 5));
  73.             }
  74.         while ((hit != ok) && (hit != cancel));
  75.         
  76.         if ((hit == ok) && (theSettings != nil))
  77.             {
  78.              hit = GetItemCtlValue(dPtr, 5);
  79.             (**theSettings).doInvert = hit;
  80.             
  81.             WriteSettings(theSettings);
  82.             }
  83.             
  84.         DisposDialog(dPtr);
  85.         }
  86.         
  87. } // DoSetupDialog
  88.  
  89.  
  90. /* ------------------------------------------------------------------------------------    */
  91. #pragma segment Initialize
  92.  
  93. SettingsHandle    GetSettings()
  94. {
  95.     SettingsHandle    aSetup;
  96.     
  97.     aSetup = (SettingsHandle) Get1Resource(kSettingsType, kSettingsID);
  98.     if (aSetup == nil)
  99.         {
  100.         aSetup = (SettingsHandle)NewHandle(sizeof(SettingsRecord));
  101.         if (aSetup != nil)
  102.             {
  103.             (**aSetup).isResource = false;
  104.             (**aSetup).doInvert = false;
  105.             }
  106.         }
  107.     else
  108.         {
  109.         (**aSetup).isResource = true;
  110.         }
  111.         
  112.     return(aSetup);
  113.         
  114. } // GetSettings
  115.  
  116. /* ------------------------------------------------------------------------------------    */
  117. #pragma segment Initialize
  118.  
  119. void WriteSettings(SettingsHandle theSettings)
  120. {
  121.     Str255    aString;
  122.     
  123.     if (theSettings == nil)
  124.         return;
  125.         
  126.     if ((**theSettings).isResource)
  127.         {
  128.         ChangedResource((Handle) theSettings);
  129.         WriteResource((Handle) theSettings);
  130.         }
  131.     else
  132.         {
  133.         aString[0] = 0;
  134.         AddResource((Handle) theSettings, kSettingsType, kSettingsID, aString);
  135.         WriteResource((Handle) theSettings);
  136.         }
  137.         
  138. } // WriteSettings
  139.  
  140.  
  141. /* ------------------------------------------------------------------------------------    */
  142. #pragma segment Initialize
  143.  
  144. BlackoutHandle    PreflightBlackout(
  145.     long * minSleepTime,
  146.     long * maxSleepTime)    
  147. {
  148.  
  149.     BlackoutHandle    theBlackout;
  150.     
  151.     /* Create our new Blackout's state information */
  152.     theBlackout = (BlackoutHandle)NewHandle(sizeof(BlackoutRecord));
  153.     
  154.     /* Inform the application of our desired sleepTime */
  155.     *minSleepTime = 30;
  156.     *maxSleepTime = 30;
  157.     
  158.     /* Return the created Blackout */
  159.     return(theBlackout);
  160.     
  161. } // PreflightBlackout
  162.  
  163. /* ------------------------------------------------------------------------------------    */
  164. #pragma segment Initialize
  165.  
  166. Boolean    InitBlackout(
  167.     BlackoutHandle    theBlackout,    // context storage
  168.     WindowPtr blackoutWindow)         // window to Blackout into
  169. /*
  170.     Routine should allocate and return any storage it needs for state
  171.     information.  NIL if none is needed.
  172.     
  173.     In addition, the sleepTime parameter should be changed to the value which will
  174.     be passed for the sleep parameter to WaitNextEvent.
  175.     
  176.     return true if this function should continue, false if the fader
  177.     should stop right now.
  178. */
  179. {
  180.     SettingsHandle    theSettings;
  181.     
  182.     /* Store away any useful information we need */
  183.     if (theBlackout != nil)
  184.         {
  185.         (**theBlackout).maxRect = blackoutWindow->portRect;
  186.         theSettings = GetSettings();
  187.         (**theBlackout).theSettings = theSettings;
  188.         
  189.         PaintRect(&blackoutWindow->portRect);        
  190.         }
  191.         
  192.     
  193.     return(true);
  194.     
  195. } // InitBlackout
  196.  
  197. /* ------------------------------------------------------------------------------------    */
  198. #pragma segment Terminate
  199.  
  200. void    DisposeBlackout(BlackoutHandle theBlackout)
  201. /*
  202.     Routine should dispose of any storage which was created and do any final
  203.     cleanup before the window is disposed of.
  204. */
  205. {
  206.     if (theBlackout != nil)
  207.         DisposHandle((Handle) theBlackout);
  208.         
  209. } // DisposeBlackout
  210.  
  211. /* ------------------------------------------------------------------------------------    */
  212. #pragma segment Main
  213.  
  214. Boolean    BlackoutEvent(EventRecord *theEvent)
  215. /*
  216.     Return false to let the shell handle the event
  217. */
  218. {
  219. #pragma unused (theEvent)
  220.  
  221.     return(false);
  222.     
  223. } // BlackoutEvent
  224.  
  225. /* ------------------------------------------------------------------------------------    */
  226. #pragma segment Main
  227.  
  228. void    BlackoutIdle(WindowPtr blackoutWindow, BlackoutHandle theBlackout)
  229. /*
  230.     Called to idle the Blackout effect.  Do something creative here.
  231. */
  232. {
  233. #pragma unused (blackoutWindow)
  234.  
  235.     Rect    theRect;
  236.     
  237.     if (theBlackout == nil) 
  238.         return;
  239.         
  240.     if ((**theBlackout).theSettings == nil)
  241.         return;
  242.         
  243.     if ( (**(**theBlackout).theSettings).doInvert)
  244.         {
  245.         theRect = (**theBlackout).maxRect;
  246.         InvertRect(&theRect);
  247.         }
  248.         
  249. } // BlackoutIdle
  250.  
  251.